package leetcode_tag.树;

import leetcode.TreeNode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class LeetCode173 {

    private int cursor;

    private List<Integer> list;

    // 中序遍历
    public LeetCode173(TreeNode root) {
        this.cursor = 0;
        this.list = new LinkedList<>();
        helper(root);
    }

    private void helper(TreeNode node) {
        if (node == null)
            return;
        helper(node.left);
        list.add(node.val);
        helper(node.right);
    }

    /**
     * @return the next smallest number
     */
    public int next() {
        return list.get(cursor++);
    }

    /**
     * @return whether we have a next smallest number
     */
    public boolean hasNext() {
        return cursor < list.size();
    }

}
